﻿<!-- saved from url=(0014)about:internet -->
<html>
<head>
    <title></title>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
    <script type="text/javascript">
        google.load("earth", "1");
        google.load('maps', '2.x', { 'other_params': 'sensor=false' });
        var ge;
        var geocoder;
        function init() {

            google.earth.createInstance('earth', initCallback, failureCB);
            geocoder = new GClientGeocoder();
            
        }

        function initCallback(instance) {
            ge = instance;
            ge.getWindow().setVisibility(true);
			ge.getLayerRoot().enableLayerById(ge.LAYER_BUILDINGS, true);
			setTimeout("ge.getOptions().setFlyToSpeed(ge.SPEED_TELEPORT);", 2000);
            doGeocode('50 avenue des Champs-élysées, 75008 Paris, France');
        }
        function failureCB(errorCode) {
            alert(errorCode);
        }
        function doGeocode(address) {
            geocoder.getLatLng(address, function (point) {
                if (point) {
                    var lookAt = ge.createLookAt('');
                    lookAt.set(point.y, point.x, 10, ge.ALTITUDE_RELATIVE_TO_GROUND, 0, 30, 200);
                    ge.getView().setAbstractView(lookAt);
                }
            });
        }
        google.setOnLoadCallback(init);
        function setLongitude(lookAt, speed) {
            lookAt.setLongitude(lookAt.getLongitude() + speed);
            ge.getView().setAbstractView(lookAt);
        }

        function setLatitude(lookAt, speed) {
            lookAt.setLatitude(lookAt.getLatitude() + speed);
            ge.getView().setAbstractView(lookAt);
        }
        function tiltLookAt(lookAt, angle) {
            lookAt.setTilt(lookAt.getTilt() + angle);
            ge.getView().setAbstractView(lookAt);
        }
        function tiltCamera(camera, angle) {
            camera.setTilt(camera.getTilt() + angle);
            ge.getView().setAbstractView(camera);
        }
        function rollCamera(camera, angle) {
            camera.setRoll(camera.getRoll() + angle);
            ge.getView().setAbstractView(camera);
        }
        function zoom(camera, altitude) {
            camera.setAltitude(altitude);
            ge.getView().setAbstractView(camera);
        }

        $(document).keypress(function (e) {
            var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
            var camera = ge.getView().copyAsCamera(ge.ALTITUDE_RELATIVE_TO_GROUND);
            if (e.which == 106) setLongitude(lookAt, -0.0001); //j
            if (e.which == 108) setLongitude(lookAt, 0.0001); //l
            if (e.which == 105) setLatitude(lookAt, 0.0001); //i
            if (e.which == 107) setLatitude(lookAt, -0.0001); //k
            if (e.which == 112) tiltLookAt(lookAt, -3); //p
            if (e.which == 109) tiltLookAt(lookAt, 3); //m
            if (e.which == 117) rollCamera(camera, -3); //u
            if (e.which == 111) rollCamera(camera, 3); //o
            if (e.which == 121) tiltCamera(camera, -3); //y : up
            if (e.which == 104) tiltCamera(camera, 3); //h : down
            if (e.which == 45) zoom(camera, camera.getAltitude() / 1.2); //-
            if (e.which == 43) zoom(camera, camera.getAltitude() * 1.2); //+
        });
    </script>
    <script type="text/javascript">
        $().ready(function () {
            jKinect.initKinect(true, false, undefined, Bind);
        });

        function Bind() {
            jKinect.bind("SkeletonFrameReady", function (joints) {
                if (ge != undefined && ge.getView() != undefined) {
                    var camera = ge.getView().copyAsCamera(ge.ALTITUDE_RELATIVE_TO_GROUND);
                    if (joints["Head"].Z - joints["HipCenter"].Z < -0.15 || joints["Head"].Z - joints["HipCenter"].Z > 0.1)
                        zoom(camera, camera.getAltitude() * (Math.abs(1.0 + (joints["Head"].Z - joints["HipCenter"].Z) / 2.0)));
                    if (joints["HandLeft"].Z < joints["Head"].Z - .20
                        && joints["HandRight"].Z < joints["Head"].Z - .20) {
                        if (Math.abs(joints["HandLeft"].Y - joints["HandRight"].Y) > .1) {
                            var handsAngle = Math.atan2(joints["HandLeft"].Y - joints["HandRight"].Y, joints["HandLeft"].X - joints["HandRight"].X);
                            camera.setRoll(handsAngle);
                        }
                        var handsCenter = jKinect.barycentric(joints["HandLeft"], joints["HandRight"]);
                        var handsDistance = jKinect.distance(joints["HandLeft"], joints["HandRight"]);
                        var armHeadAngle = Math.atan2(handsCenter.Y - joints["Head"].Y, handsCenter.X - joints["Head"].X);
                        camera.setTilt(camera.getTilt() + armHeadAngle / 2);
                        camera.setAltitude(camera.getAltitude() + 0.1 * camera.getAltitude() *(0.4 - Math.abs(joints["HandLeft"].X - joints["HandRight"].X)));
                        ge.getView().setAbstractView(camera);
                    }
                }
            });

            jKinect.bind("HandPosition", function (position) {
                if (position.X != -200 && position.Y != -200) {
                    var camera = ge.getView().copyAsCamera(ge.ALTITUDE_RELATIVE_TO_GROUND);
                    var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
                    lookAt.setLatitude(lookAt.getLatitude() + position.Y * (camera.getAltitude() / 1000000));
                    lookAt.setLongitude(lookAt.getLongitude() + position.X * (camera.getAltitude() / 1000000));
                    ge.getView().setAbstractView(lookAt);
                }
            });
            setInterval("jKinect.getNextSkeletonFrame()", 50);
        }
    </script>
</head>
<body>
    <div id="earth" style="height: 100%; width: 100%;">
    </div>
</body>
</html>
